
#line 1 "lexer.rl"
#include "lexer.h"
#include <cstdlib>
#include <string>
#include <tchar.h>



#line 8 "lexer.cpp"
static const char _Lexer_actions[] = {
	0, 1, 0, 1, 1, 1, 2, 1, 
	5, 1, 6, 1, 7, 1, 8, 1, 
	9, 1, 10, 1, 11, 1, 12, 1, 
	13, 1, 14, 1, 15, 1, 16, 2, 
	2, 3, 2, 2, 4
};

static const char _Lexer_key_offsets[] = {
	0, 0, 2, 5, 7, 26, 38, 42, 
	44, 53, 63
};

static const unsigned long _Lexer_trans_keys[] = {
	48u, 57u, 45u, 48u, 57u, 48u, 57u, 32u, 
	40u, 41u, 42u, 43u, 45u, 47u, 94u, 95u, 
	9u, 10u, 48u, 57u, 65u, 90u, 97u, 122u, 
	1024u, 1279u, 46u, 69u, 95u, 101u, 48u, 57u, 
	65u, 90u, 97u, 122u, 1024u, 1279u, 69u, 101u, 
	48u, 57u, 48u, 57u, 95u, 48u, 57u, 65u, 
	90u, 97u, 122u, 1024u, 1279u, 45u, 95u, 48u, 
	57u, 65u, 90u, 97u, 122u, 1024u, 1279u, 95u, 
	48u, 57u, 65u, 90u, 97u, 122u, 1024u, 1279u, 
	0
};

static const char _Lexer_single_lengths[] = {
	0, 0, 1, 0, 9, 4, 2, 0, 
	1, 2, 1
};

static const char _Lexer_range_lengths[] = {
	0, 1, 1, 1, 5, 4, 1, 1, 
	4, 4, 4
};

static const char _Lexer_index_offsets[] = {
	0, 0, 2, 5, 7, 22, 31, 35, 
	37, 43, 50
};

static const char _Lexer_indicies[] = {
	1, 0, 2, 3, 0, 3, 4, 5, 
	7, 8, 9, 10, 11, 12, 15, 14, 
	5, 13, 14, 14, 14, 6, 17, 18, 
	14, 18, 13, 14, 14, 14, 16, 19, 
	19, 1, 16, 3, 16, 14, 14, 14, 
	14, 14, 20, 2, 14, 21, 14, 14, 
	14, 20, 14, 21, 14, 14, 14, 16, 
	0
};

static const char _Lexer_trans_targs[] = {
	4, 6, 3, 7, 4, 4, 0, 4, 
	4, 4, 4, 4, 4, 5, 8, 4, 
	4, 1, 9, 2, 4, 10
};

static const char _Lexer_trans_actions[] = {
	27, 31, 0, 0, 29, 21, 0, 7, 
	9, 15, 11, 13, 17, 5, 0, 19, 
	23, 0, 34, 0, 25, 0
};

static const char _Lexer_to_state_actions[] = {
	0, 0, 0, 0, 1, 0, 0, 0, 
	0, 0, 0
};

static const char _Lexer_from_state_actions[] = {
	0, 0, 0, 0, 3, 0, 0, 0, 
	0, 0, 0
};

static const char _Lexer_eof_trans[] = {
	0, 1, 1, 5, 0, 17, 17, 17, 
	21, 21, 17
};

static const int Lexer_start = 4;
static const int Lexer_first_final = 4;
static const int Lexer_error = 0;

static const int Lexer_en_main = 4;


#line 55 "lexer.rl"


Calc::Lexer::Lexer(_TCHAR const* p_, _TCHAR const* pe_)
  : p(p_)
  , pe(pe_)
  , eof(pe_)
{
  
#line 100 "lexer.cpp"
	{
	cs = Lexer_start;
	ts = 0;
	te = 0;
	act = 0;
	}

#line 63 "lexer.rl"
}


Calc::Parser::token_type Calc::Lexer::lex(Parser::semantic_type* val)
{
  Parser::token_type ret = Parser::token::END;
  
#line 112 "lexer.cpp"
	{
	int _klen;
	unsigned int _trans;
	const char *_acts;
	unsigned int _nacts;
	const unsigned long *_keys;

	if ( p == pe )
		goto _test_eof;
	if ( cs == 0 )
		goto _out;
_resume:
	_acts = _Lexer_actions + _Lexer_from_state_actions[cs];
	_nacts = (unsigned int) *_acts++;
	while ( _nacts-- > 0 ) {
		switch ( *_acts++ ) {
	case 1:
#line 1 "NONE"
	{ts = p;}
	break;
#line 131 "lexer.cpp"
		}
	}

	_keys = _Lexer_trans_keys + _Lexer_key_offsets[cs];
	_trans = _Lexer_index_offsets[cs];

	_klen = _Lexer_single_lengths[cs];
	if ( _klen > 0 ) {
		const unsigned long *_lower = _keys;
		const unsigned long *_mid;
		const unsigned long *_upper = _keys + _klen - 1;
		while (1) {
			if ( _upper < _lower )
				break;

			_mid = _lower + ((_upper-_lower) >> 1);
			if ( (*p) < *_mid )
				_upper = _mid - 1;
			else if ( (*p) > *_mid )
				_lower = _mid + 1;
			else {
				_trans += (unsigned int)(_mid - _keys);
				goto _match;
			}
		}
		_keys += _klen;
		_trans += _klen;
	}

	_klen = _Lexer_range_lengths[cs];
	if ( _klen > 0 ) {
		const unsigned long *_lower = _keys;
		const unsigned long *_mid;
		const unsigned long *_upper = _keys + (_klen<<1) - 2;
		while (1) {
			if ( _upper < _lower )
				break;

			_mid = _lower + (((_upper-_lower) >> 1) & ~1);
			if ( (*p) < _mid[0] )
				_upper = _mid - 2;
			else if ( (*p) > _mid[1] )
				_lower = _mid + 2;
			else {
				_trans += (unsigned int)((_mid - _keys)>>1);
				goto _match;
			}
		}
		_trans += _klen;
	}

_match:
	_trans = _Lexer_indicies[_trans];
_eof_trans:
	cs = _Lexer_trans_targs[_trans];

	if ( _Lexer_trans_actions[_trans] == 0 )
		goto _again;

	_acts = _Lexer_actions + _Lexer_trans_actions[_trans];
	_nacts = (unsigned int) *_acts++;
	while ( _nacts-- > 0 )
	{
		switch ( *_acts++ )
		{
	case 2:
#line 1 "NONE"
	{te = p+1;}
	break;
	case 3:
#line 25 "lexer.rl"
	{act = 1;}
	break;
	case 4:
#line 35 "lexer.rl"
	{act = 2;}
	break;
	case 5:
#line 38 "lexer.rl"
	{te = p+1;{ret = Parser::token::LPAREN; {p++; goto _out; }}}
	break;
	case 6:
#line 40 "lexer.rl"
	{te = p+1;{ret = Parser::token::RPAREN; {p++; goto _out; }}}
	break;
	case 7:
#line 42 "lexer.rl"
	{te = p+1;{ret = Parser::token::PLUS; {p++; goto _out; }}}
	break;
	case 8:
#line 44 "lexer.rl"
	{te = p+1;{ret = Parser::token::MINUS; {p++; goto _out; }}}
	break;
	case 9:
#line 46 "lexer.rl"
	{te = p+1;{ret = Parser::token::MUL; {p++; goto _out; }}}
	break;
	case 10:
#line 48 "lexer.rl"
	{te = p+1;{ret = Parser::token::DIV; {p++; goto _out; }}}
	break;
	case 11:
#line 50 "lexer.rl"
	{te = p+1;{ret = Parser::token::POW; {p++; goto _out; }}}
	break;
	case 12:
#line 52 "lexer.rl"
	{te = p+1;}
	break;
	case 13:
#line 25 "lexer.rl"
	{te = p;p--;{ret = Parser::token::NUM;
          *val = strtod(std::string(ts, te).c_str(), 0);
          {p++; goto _out; }}}
	break;
	case 14:
#line 35 "lexer.rl"
	{te = p;p--;{ ret = Parser::token::IDENTIFIER; {p++; goto _out; }}}
	break;
	case 15:
#line 25 "lexer.rl"
	{{p = ((te))-1;}{ret = Parser::token::NUM;
          *val = strtod(std::string(ts, te).c_str(), 0);
          {p++; goto _out; }}}
	break;
	case 16:
#line 1 "NONE"
	{	switch( act ) {
	case 1:
	{{p = ((te))-1;}ret = Parser::token::NUM;
          *val = strtod(std::string(ts, te).c_str(), 0);
          {p++; goto _out; }}
	break;
	case 2:
	{{p = ((te))-1;} ret = Parser::token::IDENTIFIER; {p++; goto _out; }}
	break;
	}
	}
	break;
#line 255 "lexer.cpp"
		}
	}

_again:
	_acts = _Lexer_actions + _Lexer_to_state_actions[cs];
	_nacts = (unsigned int) *_acts++;
	while ( _nacts-- > 0 ) {
		switch ( *_acts++ ) {
	case 0:
#line 1 "NONE"
	{ts = 0;}
	break;
#line 266 "lexer.cpp"
		}
	}

	if ( cs == 0 )
		goto _out;
	if ( ++p != pe )
		goto _resume;
	_test_eof: {}
	if ( p == eof )
	{
	if ( _Lexer_eof_trans[cs] > 0 ) {
		_trans = _Lexer_eof_trans[cs] - 1;
		goto _eof_trans;
	}
	}

	_out: {}
	}

#line 70 "lexer.rl"
  return ret;
}